import ROSLIB from "roslib";

/**
 * 向连接目标发送保存地图的命令
 * @param {ROSLIB.Ros} roslink Ros连接
 * @param {String} filename 保存文件名
 * @param {Object} self 可用于传入组件环境的this指针
 * @param {Function} callback 回调函数
 */
function saveMapByService(roslink, filename, self, callback) {

    if (typeof filename == "string") {
        console.log("filemane type:" + typeof filename + "  filename: " + filename);
    }
    var saveClient = new ROSLIB.Service({
        ros: roslink,
        name: "/add_two_ints",
        serviceType: "rospy_tutorials/AddTwoInts"
    });

    var request = new ROSLIB.ServiceRequest({
        name: "save",
        a: 0,
        p: filename
    });

    saveClient.callService(request, function (result) {
        console.log("Result for service call on " +
            saveClient.name +
            ": " +
            result.feedback);
        callback(self);
    });
}

export { saveMapByService };